<template>
  <div id="login">
    <!-- 登录 -->
    <div v-if="status === 0" class="user_msg">
      <div class="bg">
        <div class="title">
          <h2>Login</h2>
        </div>
        <div class="input_msg">
          <div class="input_box" v-for="item in loginMsg" :key="item.id">
            <InputMsg :msg="item" />
          </div>
          <div class="authcode">
            <inputMsg :msg="authcode">
              <AuthCode />
            </inputMsg>
          </div>
        </div>
        <div class="btn">
          <LoginButton />
        </div>
        <div class="help">
          <span @click="status = 1">注册</span>
          <span @click="status = 2">忘记密码</span>
        </div>
      </div>
    </div>
    <!-- 注册 -->
    <div v-else-if="status === 1" class="user_msg">
      <div class="title">
        <h2>SignIn</h2>
      </div>
      <div class="input_msg">
        <div class="input_box" v-for="item in signinMsg" :key="item.id">
          <InputMsg :msg="item" />
        </div>
        <div class="authcode">
          <inputMsg :msg="authcode">
            <SendCode />
          </inputMsg>
        </div>
      </div>
      <div class="btn">
        <SignInButton />
      </div>
      <div class="help">
        <span @click="status = 0">返回</span>
        <span></span>
      </div>
    </div>
    <!-- 忘记密码 -->
    <div v-else class="user_msg">
      <div class="title">
        <h2>Find Password</h2>
      </div>
      <div class="input_msg">
        <div class="input_box" v-for="item in forgetMsg" :key="item.id">
          <InputMsg :msg="item" />
        </div>
        <div class="authcode">
          <inputMsg :msg="authcode">
            <SendCode />
          </inputMsg>
        </div>
      </div>
      <div class="btn">
        <ForgetButton />
      </div>
      <div class="help">
        <span @click="status = 0">返回</span>
        <span></span>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'

import InputMsg from '../../components/Login/InputMsg.vue'
import AuthCode from '../../components/Login/AuthCode.vue'
import LoginButton from '../../components/Button/LoginButton.vue'
import SendCode from '../../components/Button/SendCode.vue'
import SignInButton from '../../components/Button/SignInButton.vue'
import ForgetButton from '../../components/Button/ForgetButton.vue'

import { Back } from '@/utils/utils'

function getInputMsg() {
  const loginMsg = [
    {
      id: 0,
      title: '用户名/邮箱',
      name: 'admin',
      type: 'text',
      test: 'test1'
    },
    {
      id: 1,
      title: '密码',
      name: 'password',
      type: 'password',
      switch_type: 'text',
      test: '1123456'
    }
  ]
  const signinMsg = [
    {
      id: 0,
      title: '邮箱',
      name: 'email',
      type: 'email',
      switch_type: 'text',
      test: ''
    },
    {
      id: 1,
      title: '用户名',
      name: 'admin',
      type: 'text',
      test: ''
    },
    {
      id: 2,
      title: '密码',
      name: 'password',
      type: 'password',
      switch_type: 'text',
      test: ''
    }
  ]
  const forgetMsg = [
    {
      id: 0,
      title: '邮箱',
      name: 'email',
      type: 'email',
      switch_type: 'text',
      test: ''
    },
    {
      id: 1,
      title: '新密码',
      name: 'password',
      type: 'password',
      switch_type: 'text',
      test: ''
    }
  ]

  const authcode = {
    title: '验证码',
    name: 'authcode',
    type: 'text',
    test: ''
  }

  const status = ref(0)

  return {
    loginMsg,
    signinMsg,
    forgetMsg,
    authcode,
    status,
    Back
  }
}
export default {
  name: 'Login',
  components: {
    InputMsg,
    AuthCode,
    LoginButton,
    SendCode,
    SignInButton,
    ForgetButton
  },
  setup() {
    const active = ref(0)
    return {
      active,
      ...getInputMsg()
    }
  }
}
</script>

<style lang="scss" scoped>
$radius: 12px;
#login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  transform-style: preserve-3d;
  perspective: 100px;
}
.user_msg {
  padding: 30px;
  box-sizing: border-box;
  background-color: $aside_bg;
  border-radius: $radius;
  transform: translateZ(-150px);
  opacity: 0;
  animation: run 0.625s forwards;
  .title {
    color: $font;
    margin-bottom: 20px;
    h2 {
      text-align: center;
      font-size: 30px;
    }
  }
  .input_msg {
    display: flex;
    flex-direction: column;
    gap: 20px;
    .input_box {
      cursor: pointer;
      width: 380px;
    }
    .active {
      border: 1px solid $primary;
    }
  }
}
@keyframes run {
  100% {
    opacity: 1;
    transform: translateZ(0);
  }
}
.btn {
  margin-top: 20px;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
}
.help {
  padding: 0 8px;
  box-sizing: border-box;
  margin-top: 15px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  span {
    cursor: pointer;
    font-size: 14px;
    color: $primary;
  }
}
</style>
